﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;

namespace StockShark.Models
{
    // zlecenia kupna/sprzedazy
    public class Order
    {
        public int Id { get; set; }
        public int BrokerageAccountId { get; set; }
        public int PaperId { get; set; }
        [Range(1, 999999)]
        [Display(Name = "Ilość")]
        public int Quantity { get; set; }
        [Display(Name = "Zezwól na wykonywanie części zlecenia")]
        public bool AllowPartial { get; set; }
        [Display(Name = "Limit ceny")]
        [Range(0, 999999, ErrorMessage="Limit ceny nie może być ujemny")]
        public decimal PriceLimit { get; set; }
        public bool BuyNotSell { get; set; }
        [DisplayFormat(DataFormatString = "{0:g}")]
        public DateTime IssuingDate { get; set; }
        [DataType(DataType.Date)]
        [DisplayFormat(ApplyFormatInEditMode = true, DataFormatString = "{0:d}")]
        [Display(Name = "Data ważności")]
        public DateTime Deadline { get; set; }
        public virtual Instrument Paper { get; set; }
        public virtual BrokerageAccount BrokerageAccount { get; set; }

        public int DaysToEnd {
            get
            {
                return (Deadline - DateTime.Now).Days + 1;
            }
        }

        public decimal Total
        {
            get
            {
                if (Paper != null)
                    return Quantity * Paper.CurrentPrice;
                return 0;
            }
        }
    }
}